package com.eternal.util.user.controller;


import com.eternal.Exception.ResultEnum;
import com.eternal.Exception.ResultVo;
import com.eternal.util.user.entity.UserInfo;
import com.eternal.util.user.service.UserInfoService;
import com.eternal.util.user.service.UserUtil;
import com.eternal.util.user.vo.UserVo;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户基础表 前端控制器
 * </p>
 *
 * @author Eternal
 * @since 2018-08-26
 */
@RestController
@RequestMapping("/userInfo")
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;

    @GetMapping("/queryUserInfo")
    @RequiresPermissions("userInfo_queryUserInfo")
    public ResultVo<UserInfo> queryUserInfo(String userId) {
        UserInfo userInfo = userInfoService.getUserInfo(userId);
        return new ResultVo<>(userInfo);
    }

    @GetMapping("/queryUserAllInfo")
    @RequiresPermissions("userInfo_queryUserAllInfo")
    public ResultVo<UserVo> queryUserAllInfo(String userId){
        UserVo userAllInfo = userInfoService.getUserAllInfo(userId);
        return new ResultVo<>(userAllInfo);
    }


    @GetMapping("/queryMyInfo")
    public ResultVo<UserVo> queryMyInfo(){
       return new ResultVo<>(UserUtil.getUser());
    }



    @PostMapping("/registerUser")
    public ResultVo registerUser(UserInfo userInfo){
        boolean registerUser = userInfoService.registerUser(userInfo);
        return new ResultVo(registerUser?ResultEnum.SUCCESS:ResultEnum.REGISTER_USER_ERROR);
    }

    @GetMapping("/queryIsUser")
    public ResultVo queryIsUser(String userId){
        boolean registerUser = userInfoService.queryIsUser(userId);
        return new ResultVo(registerUser?ResultEnum.SUCCESS:ResultEnum.REGISTER_USER_ERROR);
    }

}

